<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Admin.Master" Inherits="System.Web.Mvc.ViewPage" %>

<script runat="server">
    int i = 0;
    int j = 0;

    protected void LinkButton3_Click(object sender, EventArgs e)
    {
        i = Convert.ToInt32(Request.QueryString["id"]);
        j = Convert.ToInt32(Request.QueryString["aa"]);
        SqlDataSource1.InsertParameters[0].DefaultValue = (GridView1.FooterRow.FindControl("TextBox1") as TextBox).Text;
        SqlDataSource1.InsertParameters[1].DefaultValue = (GridView1.FooterRow.FindControl("TextBox2") as TextBox).Text;
        SqlDataSource1.InsertParameters[2].DefaultValue = (GridView1.FooterRow.FindControl("TextBox3") as TextBox).Text;
        //SqlDataSource1.InsertParameters[3].DefaultValue = (GridView1.FooterRow.FindControl("TextBox4") as TextBox).Text;
        //SqlDataSource1.InsertParameters[3].DefaultValue = (GridView1.FooterRow.FindControl("d1") as DropDownList).Text;
        SqlDataSource1.InsertParameters[3].DefaultValue = Convert.ToString(i);
        SqlDataSource1.InsertParameters[4].DefaultValue = Convert.ToString(j);
        /*
        SqlDataSource1.InsertParameters[4].DefaultValue = (GridView1.FooterRow.FindControl("d2") as DropDownList).Text;
        SqlDataSource1.InsertParameters[5].DefaultValue = (GridView1.FooterRow.FindControl("TextBox6") as TextBox).Text;
        SqlDataSource1.InsertParameters[6].DefaultValue = (GridView1.FooterRow.FindControl("TextBox7") as TextBox).Text;
        SqlDataSource1.InsertParameters[7].DefaultValue = (GridView1.FooterRow.FindControl("TextBox8") as TextBox).Text;
        SqlDataSource1.InsertParameters[8].DefaultValue = (GridView1.FooterRow.FindControl("TextBox9") as TextBox).Text;
        
        SqlDataSource1.InsertParameters[9].DefaultValue = (GridView1.FooterRow.FindControl("TextBox10") as TextBox).Text;
        SqlDataSource1.InsertParameters[10].DefaultValue = (GridView1.FooterRow.FindControl("TextBox11") as TextBox).Text;
        SqlDataSource1.InsertParameters[11].DefaultValue = (GridView1.FooterRow.FindControl("TextBox12") as TextBox).Text;
        SqlDataSource1.InsertParameters[12].DefaultValue = (GridView1.FooterRow.FindControl("TextBox13") as TextBox).Text;
         */
        SqlDataSource1.InsertParameters[5].DefaultValue = "1";
        SqlDataSource1.Insert();       
    }


    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Detail")
        {
            string id = (GridView1.Rows[Convert.ToInt32(e.CommandArgument)].FindControl("Label4") as Label).Text;
            Response.Redirect("/Admin/ManageCourse/?id=" + id);
        }
    }
</script>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	ManageCourseOfMajor
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h1> MANAGE COURSES OF MAJOR </h1>
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
            CellPadding="4" DataKeyNames="ID" DataSourceID="SqlDataSource1" 
            ForeColor="#333333" GridLines="None" ShowFooter="True" 
        onrowcommand="GridView1_RowCommand" Width="1158px">
            <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
            <Columns>
                <asp:TemplateField HeaderText="ID" InsertVisible="False" SortExpression="ID">
                    <EditItemTemplate>
                        <asp:Label ID="Label1" runat="server" Text='<%# Eval("ID") %>'></asp:Label>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label4" runat="server" Text='<%# Bind("ID") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="CourseCode" SortExpression="CourseCode">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("CourseCode") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <FooterTemplate>
                        <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("CourseCode") %>'></asp:TextBox>
                    </FooterTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label1" runat="server" Text='<%# Bind("CourseCode") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="CourseEnglishName" 
                    SortExpression="CourseEnglishName">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox2" runat="server" 
                            Text='<%# Bind("CourseEnglishName") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <FooterTemplate>
                        <asp:TextBox ID="TextBox2" runat="server" 
                            Text='<%# Bind("CourseEnglishName") %>'></asp:TextBox>
                    </FooterTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label2" runat="server" Text='<%# Bind("CourseEnglishName") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="CourseVietnameseName" 
                    SortExpression="CourseVietnameseName">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox3" runat="server" 
                            Text='<%# Bind("CourseVietnameseName") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <FooterTemplate>
                        <asp:TextBox ID="TextBox3" runat="server" 
                            Text='<%# Bind("CourseVietnameseName") %>'></asp:TextBox>
                    </FooterTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label3" runat="server" 
                            Text='<%# Bind("CourseVietnameseName") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="KBName" SortExpression="KBName">
                    <EditItemTemplate>
                        <asp:SqlDataSource ID="d1" runat="server" 
                            ConnectionString="<%$ ConnectionStrings:CDIO1ConnectionString1 %>" 
                            SelectCommand="SELECT [ID], [Name] FROM [KnowledgeBlock]">
                        </asp:SqlDataSource>
                        <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="d1" 
                            DataTextField="Name" DataValueField="ID" 
                            SelectedValue='<%# Bind("KnowledgeBlockID") %>'>
                        </asp:DropDownList>
                    </EditItemTemplate>
                    <FooterTemplate>
                        <asp:DropDownList ID="d1" runat="server" DataSourceID="data2" DataTextField="Name" 
                            DataValueField="ID">
                        </asp:DropDownList>
                        <asp:SqlDataSource ID="data2" runat="server" 
                            ConnectionString="<%$ ConnectionStrings:CDIO1ConnectionString1 %>" 
                            SelectCommand="SELECT [ID], [Name] FROM [KnowledgeBlock]"></asp:SqlDataSource>
                    </FooterTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label15" runat="server" Text='<%# Bind("KBName") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="KnowledgeBlockID" 
                    SortExpression="KnowledgeBlockID" Visible="False"></asp:TemplateField>
                <asp:TemplateField HeaderText="MajorName" SortExpression="MajorName">
                    <EditItemTemplate>
                        <asp:DropDownList ID="DropDownList2" runat="server" DataSourceID="a" 
                            DataTextField="Name" DataValueField="ID" 
                            SelectedValue='<%# Bind("MajorInChargeID") %>'>
                        </asp:DropDownList>
                        <asp:SqlDataSource ID="a" runat="server" 
                            ConnectionString="<%$ ConnectionStrings:CDIO1ConnectionString1 %>" 
                            SelectCommand="SELECT [ID], [Name] FROM [Major]"></asp:SqlDataSource>
                    </EditItemTemplate>
                    <FooterTemplate>
                        <asp:DropDownList ID="d2" runat="server" DataSourceID="b" DataTextField="Name" 
                            DataValueField="ID">
                        </asp:DropDownList>
                        <asp:SqlDataSource ID="b" runat="server" 
                            ConnectionString="<%$ ConnectionStrings:CDIO1ConnectionString1 %>" 
                            SelectCommand="SELECT [ID], [Name] FROM [Major]"></asp:SqlDataSource>
                    </FooterTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label14" runat="server" Text='<%# Bind("MajorName") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="MajorInChargeID" 
                    SortExpression="MajorInChargeID" Visible="False">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox4" runat="server" 
                            Text='<%# Bind("KnowledgeBlockID") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox5" runat="server" Text='<%# Bind("MajorInChargeID") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <FooterTemplate>
                        <asp:TextBox ID="TextBox5" runat="server" Text='<%# Bind("MajorInChargeID") %>'></asp:TextBox>
                    </FooterTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label4" runat="server" Text='<%# Bind("KnowledgeBlockID") %>'></asp:Label>
                    </ItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label5" runat="server" Text='<%# Bind("MajorInChargeID") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="TheoryCredit" SortExpression="TheoryCredit" 
                    Visible="False">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox7" runat="server" Text='<%# Bind("TheoryCredit") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <FooterTemplate>
                        <asp:TextBox ID="TextBox7" runat="server" Text='<%# Bind("TheoryCredit") %>'></asp:TextBox>
                    </FooterTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label7" runat="server" Text='<%# Bind("TheoryCredit") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="PraticeCredit" SortExpression="PraticeCredit" 
                    Visible="False">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox8" runat="server" Text='<%# Bind("PraticeCredit") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <FooterTemplate>
                        <asp:TextBox ID="TextBox8" runat="server" Text='<%# Bind("PraticeCredit") %>'></asp:TextBox>
                    </FooterTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label8" runat="server" Text='<%# Bind("PraticeCredit") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="SelfStudyCredit" 
                    SortExpression="SelfStudyCredit" Visible="False">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox9" runat="server" Text='<%# Bind("SelfStudyCredit") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <FooterTemplate>
                        <asp:TextBox ID="TextBox9" runat="server" Text='<%# Bind("SelfStudyCredit") %>'></asp:TextBox>
                    </FooterTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label9" runat="server" Text='<%# Bind("SelfStudyCredit") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="RegisterCondition" 
                    SortExpression="RegisterCondition" Visible="False">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox10" runat="server" 
                            Text='<%# Bind("RegisterCondition") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <FooterTemplate>
                        <asp:TextBox ID="TextBox10" runat="server" 
                            Text='<%# Bind("RegisterCondition") %>'></asp:TextBox>
                    </FooterTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label10" runat="server" Text='<%# Bind("RegisterCondition") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Objective" SortExpression="Objective" 
                    Visible="False">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox11" runat="server" Text='<%# Bind("Objective") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <FooterTemplate>
                        <asp:TextBox ID="TextBox11" runat="server" Text='<%# Bind("Objective") %>'></asp:TextBox>
                    </FooterTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label11" runat="server" Text='<%# Bind("Objective") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="ContentIndividualSkill" 
                    SortExpression="ContentIndividualSkill" Visible="False">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox12" runat="server" 
                            Text='<%# Bind("ContentIndividualSkill") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <FooterTemplate>
                        <asp:TextBox ID="TextBox12" runat="server" 
                            Text='<%# Bind("ContentIndividualSkill") %>'></asp:TextBox>
                    </FooterTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label12" runat="server" 
                            Text='<%# Bind("ContentIndividualSkill") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="ContentGroupSkill" 
                    SortExpression="ContentGroupSkill" Visible="False">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox13" runat="server" 
                            Text='<%# Bind("ContentGroupSkill") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <FooterTemplate>
                        <asp:TextBox ID="TextBox13" runat="server" 
                            Text='<%# Bind("ContentGroupSkill") %>'></asp:TextBox>
                    </FooterTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label13" runat="server" Text='<%# Bind("ContentGroupSkill") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="Status" HeaderText="Status" SortExpression="Status" 
                    Visible="False" />
                <asp:TemplateField ShowHeader="False">
                    <EditItemTemplate>
                        <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" 
                            CommandName="Update" Text="Update"></asp:LinkButton>
                        &nbsp;<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" 
                            CommandName="Cancel" Text="Cancel"></asp:LinkButton>
                    </EditItemTemplate>
                    <FooterTemplate>
                        <asp:LinkButton ID="LinkButton3" runat="server" onclick="LinkButton3_Click">Insert</asp:LinkButton>
                    </FooterTemplate>
                    <ItemTemplate>
                        <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" 
                            CommandName="Edit" Text="Edit"></asp:LinkButton>
                        &nbsp;<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" 
                            CommandName="Delete" Text="Delete"></asp:LinkButton>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:ButtonField CommandName="Detail" Text="Detail" />
            </Columns>
            <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
            <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
            <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <EditRowStyle BackColor="#999999" />
            <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:CDIO1ConnectionString1 %>" 
            DeleteCommand="UPDATE [CourseInfo] SET [Status] = 0WHERE [ID] = @ID" 
            InsertCommand="INSERT INTO [CourseInfo] ([CourseCode], [CourseEnglishName], [CourseVietnameseName], [KnowledgeBlockID] ,[MajorInChargeID], [Status]) VALUES (@CourseCode, @CourseEnglishName, @CourseVietnameseName, @KnowledgeBlockID, @MajorInChargeID, @Status)" 
            SelectCommand="SELECT CourseInfo.ID, CourseInfo.CourseCode, CourseInfo.CourseEnglishName, CourseInfo.CourseVietnameseName, CourseInfo.KnowledgeBlockID, CourseInfo.MajorInChargeID, CourseInfo.TheoryCredit, CourseInfo.PraticeCredit, CourseInfo.SelfStudyCredit, CourseInfo.RegisterCondition, CourseInfo.Objective, CourseInfo.ContentIndividualSkill, CourseInfo.ContentGroupSkill, CourseInfo.Status, Major.Name AS MajorName, KnowledgeBlock.Name AS KBName FROM CourseInfo INNER JOIN KnowledgeBlock ON CourseInfo.KnowledgeBlockID = KnowledgeBlock.ID INNER JOIN Major ON CourseInfo.MajorInChargeID = Major.ID WHERE (CourseInfo.Status = @Status) AND (CourseInfo.KnowledgeBlockID = @KnowledgeBlockID)" 
            
            
            
            
            
        
        UpdateCommand="UPDATE [CourseInfo] SET [CourseCode] = @CourseCode, [CourseEnglishName] = @CourseEnglishName, [CourseVietnameseName] = @CourseVietnameseName, [KnowledgeBlockID] = @KnowledgeBlockID, [MajorInChargeID] = @MajorInChargeID WHERE [ID] = @ID">
            <SelectParameters>
                <asp:Parameter DefaultValue="1" Name="Status" Type="Int32" />
                <asp:QueryStringParameter Name="KnowledgeBlockID" QueryStringField="id" 
                    Type="Int32" />
            </SelectParameters>
            <DeleteParameters>
                <asp:Parameter Name="ID" Type="Int32" />
            </DeleteParameters>
            <UpdateParameters>
                <asp:Parameter Name="CourseCode" Type="String" />
                <asp:Parameter Name="CourseEnglishName" Type="String" />
                <asp:Parameter Name="CourseVietnameseName" Type="String" />
                <asp:Parameter Name="KnowledgeBlockID" Type="Int32" />
                <asp:Parameter Name="MajorInChargeID" Type="Int32" />
                <asp:Parameter Name="ID" Type="Int32" />
            </UpdateParameters>
            <InsertParameters>
                <asp:Parameter Name="CourseCode" Type="String" />
                <asp:Parameter Name="CourseEnglishName" Type="String" />
                <asp:Parameter Name="CourseVietnameseName" Type="String" />
                <asp:Parameter Name="KnowledgeBlockID" />
                <asp:Parameter Name="MajorInChargeID" Type="Int32" />
                <asp:Parameter Name="Status" Type="Int32" />
            </InsertParameters>
        </asp:SqlDataSource>
    

</asp:Content>
